﻿using System;

namespace Telex;

public readonly struct RpcHost
{
    public RpcHost(string clusterId, string serviceId)
    {
        this.clusterId = clusterId;
        this.serviceId = serviceId;
    }

    public readonly string clusterId;
    public readonly string serviceId;

    public bool IsEmpty()
    {
        return string.IsNullOrEmpty(clusterId) || string.IsNullOrEmpty(serviceId);
    }
    
    public override bool Equals(object obj)
    {
        var host = (RpcHost)obj;
        return host == this;
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(clusterId, serviceId);
    }
    
    public override string ToString()
    {
        return $"{clusterId}:{serviceId}";
    }

    public static bool operator ==(RpcHost a, RpcHost b)
    {
        return a.clusterId == b.clusterId && a.serviceId == b.serviceId;
    }

    public static bool operator !=(RpcHost a, RpcHost b)
    {
        return !(a == b);
    }
}